package com.android.xunxian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.xunxian.entry.Xunx;
import com.android.xunxian.utils.Util;
import com.oa.android.R;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 巡线
 * Created by zouqh on 2016/7/9.
 */
public class XunxAdapter extends BaseAdapter {

    private Context context;
    private List<Xunx> xunxList;

    public XunxAdapter(Context context, List<Xunx> list) {
        this.context = context;
        this.xunxList = list;
    }

    @Override
    public int getCount() {
        return xunxList.size();
    }

    @Override
    public Object getItem(int position) {
        return xunxList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.xunx_item, null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        String str=xunxList.get(position).getSPLANZT();
        viewHolder.Title.setText(xunxList.get(position).getNAME());
        viewHolder.time.setText(str+"");
        viewHolder.Content.setText(xunxList.get(position).getPLANNR());
        if(Util.NoNull(str)){
            if (str.equals("未开始")){
                viewHolder.icon.setImageResource(R.mipmap.nosurccess_route_icon);
            }else if (str.equals("执行中")){
                viewHolder.icon.setImageResource(R.mipmap.doing_route_icon);
            }else{
                viewHolder.icon.setImageResource(R.mipmap.success_rote_icon);
            }
        }else{
            viewHolder.icon.setImageResource(R.mipmap.nosurccess_route_icon);
        }

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.Title)
        TextView Title;
        @InjectView(R.id.time)
        TextView time;
        @InjectView(R.id.Content)
        TextView Content;
        @InjectView(R.id.icon)
        ImageView icon;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
